<template>
  <div class="DestinationTab-container">
    <h2 class="title">{{ title }}</h2>

    <ul class="navbar">
      <li v-for="item in tabItemDate" :key="item.id">
        <a
          :class="item.id == recommendIndex ? 'active' : ''"
          @mouseenter="setRecommendIndex(item.id)"
        >
          {{ item.title }}
        </a>
      </li>
    </ul>

    <div class="conlist">
      <a
        class="conlist-item"
        v-for="item in iteminfoItem.list"
        :key="item.id"
        @click="toTravelScenicSpot(item)"
      >
        <img v-lazy="item.picUrl" alt="" />
        <h3 class="title">{{ item.title }}</h3>
      </a>
    </div>
  </div>
</template>

<script>
import { mapState, mapActions } from "vuex";
export default {
  name: "Recommend",
  props: ["tabItemDate", "title"],
  computed: {
    ...mapState({
      recommendIndex: (state) => state.destination.recommendIndex,
    }),
    iteminfoItem: {
      get() {
        if (!this.tabItemDate) return {};
        return this.tabItemDate.find((item) => item.id == this.recommendIndex);
      },
      set(val) {
        console.log(val);
      },
    },
  },
  methods: {
    ...mapActions("destination", ["setRecommendIndex"]),
    toTravelScenicSpot(itemData) {
      if (itemData.id === "7") return;
      this.$router.push({
        path: "/TravelScenicSpot",
        query: {
          itemData: JSON.stringify(itemData),
        },
      });
    },
  },
};
</script>

<style lang="stylus" scoped>
.DestinationTab-container {
  margin-top: 30px;
  margin-bottom: 100px;
  padding-bottom: 30px;
  border-bottom: 3px solid #eee;

  .title {
    text-align: center;
    margin-bottom: 38px;
    font-size: 26px;
    font-weight: normal;
    color: #333;
    line-height: 26px;
  }

  .navbar {
    display: flex;
    justify-content: center;
    font-size: 18px;
    margin-bottom: 20px;

    li a {
      color: #333;
      display: inline-block;
      margin: 0 25px;
      vertical-align: top;
      text-decoration: none;
      padding-bottom: 10px;
      cursor: pointer;

      &.active {
        border-bottom: 3px solid #ff9d00;
        color: #ff9d00;
      }
    }
  }

  .conlist {
    width: 1000px;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;

    .conlist-item {
      margin-bottom: 10px;
      border: 1px solid #ddd;
      text-align: center;
      position: relative;
      cursor: pointer;

      &:hover {
        box-shadow: 0px 0px 10px #888888;
      }

      img {
        width: 316px;
        height: 220px;
      }

      &:nth-child(4), &:nth-child(5), &:nth-child(6), &:nth-child(7) {
        img {
          width: 230px;
          height: 220px;
        }
      }

      .title {
        position: absolute;
        bottom: 0;
        left: 0;
        width: 100%;
        text-align: left;
        padding-left: 20px;
        color: #fff;
        background-color: rgba(0, 0, 0, 0.1);
        margin-bottom: 0;
        line-height: 56px;
        box-sizing: border-box;
        font-size: 20px;
      }
    }
  }
}
</style>